﻿using ConfExpert.Forms.Base;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevTeam;

namespace ConfExpert.Forms.Depo.Kauf
{
    public partial class HF_BOMOlustur : XForm
    {
        public string idxs { get; set; }
        public HF_BOMOlustur(string idxs)
        {
            InitializeComponent();
            this.idxs = idxs;
        }

        private void HF_BOMOlustur_Load(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Maximized;

            gvBOM.Init("CreateHFBOM", idxs);
            gvBOM.AddDetailGrid(gvBOMLines, "TempId");

            gvBOMLines.Columns["Qty"].DisplayFormat.FormatString = "#,##0.###";
            gvBOMLines.MakeColumnInvisible("OrdBrand", "SezonId", "TalepTipiId", "Model");

            gvBOM.MakeColumnInvisible("IsExist");
            gvBOMLines.MakeColumnInvisible("Mukerrer");

            gvBOM.MakeReadOnly();
            gvBOMLines.MakeReadOnly("AksesuarId");

            gvBOM.BestFitColumns();
            gvBOMLines.BestFitColumns();

            gvBOM.AddSummary();
            gvBOMLines.AddSummary();

            bbiSave.ItemClick += bbiSave_ItemClick;
            gvBOM.RowCellStyle += gvBOM_RowCellStyle;
            gvBOMLines.RowCellStyle += gvBOMLines_RowCellStyle;
        }

        void gvBOMLines_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            if (e.RowHandle > -1)
            {
                bool IsMultiple = gvBOMLines.GetRowCellValue(e.RowHandle, "Mukerrer").ToBool();
                if (IsMultiple)
                    e.Appearance.BackColor = Color.Pink;
            }
        }

        void gvBOM_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            if (e.RowHandle > -1)
            {
                bool IsExist = gvBOM.GetRowCellValue(e.RowHandle, "IsExist").ToBool();
                if (IsExist)
                    e.Appearance.BackColor = Color.SkyBlue;
            }
        }

        void bbiSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gvBOMLines.EndEditing();
            string xml = gvBOMLines.Serialize();

            ExecuteNonQuery("InsHFBOM", xml, WhoAmI);
            this.DialogResult = DialogResult.OK;
        }

    }
}
